<template>
  <simple-layout title=' '>
    <!--<form class="mui-input-group">-->
      <!--<div class="mui-input-row">-->
        <!--<label>用户名</label>-->
        <!--<input type="text" class="mui-input-clear" placeholder="请输入用户名" :value="phone">-->
      <!--</div>-->
      <!--<div class="mui-input-row">-->
        <!--<label>密码</label>-->
        <!--<input type="password" class="mui-input-password" placeholder="请输入密码":value="password">-->
      <!--</div>-->
      <!--<div class="mui-input-row">-->
        <!--<label>验证码</label>-->
        <!--<input type="password" class="mui-input-password" placeholder="请输入验证码":value="code">-->
      <!--</div>-->
      <!--<div class="mui-input-row">-->
        <!--<label>邀请码</label>-->
        <!--<input type="password" class="mui-input-password" placeholder="请输入邀请码":value="inviteCode">-->
      <!--</div>-->
      <!--<div class="mui-button-row">-->
        <!--<button type="button" class="mui-btn mui-btn-primary"  @click="register()">确认</button>-->
        <!--<button type="button" class="mui-btn mui-btn-danger" >取消</button>-->
      <!--</div>-->
    <!--</form>-->

    <div class="register-top">注册账号</div>
    <form class="ab-input-group">

      <div class="ab-input-row">
        <span class="login-forget" @click="sendCode"><span :class="[numCode !== '发送验证码'? 'blue' : '']">{{ numCode }}{{numCode !== '发送验证码'? 's' : ''}}</span> {{numCode !== '发送验证码' ? '后重发' :''}}</span>
        <input type="text" class="ab-input ab-input-clear" placeholder="请输入手机号码" v-model="phone">
      </div>
      <div class="ab-input-row">
        <input type="text" class="ab-input ab-input-clear" placeholder="请输入手机验证码" v-model="code">
      </div>
      <div class="ab-input-row">
        <input type="password" class="ab-input ab-input-password mui-input-password" placeholder="请输入新密码" v-model="password">
      </div>
      <div class="ab-button-row">
        <button type="button" class="ab-btn ab-btn-primary" @click="register">同意协议并注册</button>
      </div>
      <div class="register-footer">
        <span>登陆/注册即表示您同意</span>
        <span class="register-footer-treaty" @click="registerTreaty">xxx相关协议</span>
      </div>
    </form>
  </simple-layout>
</template>


<script>
  import AuthService from '../../service/auth';
  import SimpleLayout from '../../components/SimpleLayout';

  export default {
    name: "Login",
    components: {
      //someComponent
      SimpleLayout
    },
    props: {},
    data() {
      return {
        phone:'',
        code: '',
        password: '',
        inviteCode: '',
        numCode: '发送验证码',
      }
    },
    computed: {},
    watch: {},
    mounted: function () {
      console.log(this.$cookie.get('token'))
    },
    methods: {
      // 点击查看协议
      registerTreaty() {
        //TODO
      },
      // 同意协议并注册
      loginByPwd() {
        mui.confirm('','注册成功',new Array('去登陆'),(e)=>{
          if(e.index == 0){
            this.$router.push({ name:"Login" });
          }
        });
      },
      //注册
      register() {
        const params = {
          phone:this.phone,
          code: this.code,
          password: this.$md5(this.password),
          inviteCode: '564U43',
        }
        AuthService.userReg(params).then((res) => {
          // {
          //   "type": 3,
          //   "status": "001045",
          //   "message": "推荐人不存在",
          //   "resultData": null
          // };
          if(res.status == '200'){
            console.log('注册成功')
          }else if(res.status == '001045'){
            mui.confirm('','推荐人不存在',new Array('关闭'))
          }else if(res.status == '001002'){
            mui.confirm('','手机号格式不正确',new Array('关闭'))
          }else if(res.status == '001040'){
            mui.confirm('','手机号已注册',new Array('关闭'))
          }
        })
      },
      // 点击发送验证码
      sendCode() {
        if (this.numCode !== '发送验证码') {
          return
        }
        const params = {
          phone: this.phone,
        }
        AuthService.sendCodeForRegister(params).then((res) => {
          if (res.status == 200) {
            this.numCode = 5;
            this.validateCodeClock = setInterval(() => {
              this.numCode = this.numCode - 1;
              if (this.numCode <= 0) {
                clearInterval(this.validateCodeClock);
                this.numCode = '发送验证码';
              }
            }, 1000);
          }
        })
      },

    }
  }
</script>


<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .ab-btn.ab-btn-primary{
    font-size: 20px;
  }
  .ab-input-group {
    margin-top: 60px;
  }

  .ab-input-row {
    position: relative;
    margin-top: 10px;
  }

  .ab-input {
    background: transparent;
    width: 300px;
    margin:10px;
    border-left: none;
    border-right: none;
    border-top: none;
  }

  .ab-btn-primary {
    margin-top: 50px;
    width: 300px;
    height: 40px;
    color: white;
    background: rgb(130, 130, 244);
    border-radius: 15px;
    border: 0px;
  }

  .register-footer{
    font-size: 14px;
    margin-top: 1rem;
  }
  .register-footer-treaty{

    color: blue;
  }
  .register-top{
    width: 300px;
    text-align: initial;
    margin: 6rem auto 0;
    font-size: 24px;
    font-weight: bolder;
  }
  input::-webkit-input-placeholder { /* WebKit browsers */
    color: #ccc;
  }

  input:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
    color: #ccc;
  }

  input::-moz-placeholder { /* Mozilla Firefox 19+ */
    color: #ccc;
  }

  input:-ms-input-placeholder { /* Internet Explorer 10+ */
    color: #ccc;
  }
  .login-forget{
    font-size: 16px;
    position: absolute;
    right: 13%;
    top: 34%;
    color: black;
  }
  .blue{
    color: blue;
  }
</style>
